package com.example.arcapplication.db;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.example.arcapplication.bean.HwList;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "HW_LIST".
*/
public class HwListDao extends AbstractDao<HwList, Void> {

    public static final String TABLENAME = "HW_LIST";

    /**
     * Properties of entity HwList.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Hid = new Property(0, Long.class, "hid", false, "HID");
        public final static Property Hwid = new Property(1, String.class, "hwid", false, "HWID");
        public final static Property Hwname = new Property(2, String.class, "hwname", false, "HWNAME");
    }

    private Query<HwList> inventory_HwListQuery;

    public HwListDao(DaoConfig config) {
        super(config);
    }
    
    public HwListDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"HW_LIST\" (" + //
                "\"HID\" INTEGER," + // 0: hid
                "\"HWID\" TEXT," + // 1: hwid
                "\"HWNAME\" TEXT);"); // 2: hwname
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"HW_LIST\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, HwList entity) {
        stmt.clearBindings();
 
        Long hid = entity.getHid();
        if (hid != null) {
            stmt.bindLong(1, hid);
        }
 
        String hwid = entity.getHwid();
        if (hwid != null) {
            stmt.bindString(2, hwid);
        }
 
        String hwname = entity.getHwname();
        if (hwname != null) {
            stmt.bindString(3, hwname);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, HwList entity) {
        stmt.clearBindings();
 
        Long hid = entity.getHid();
        if (hid != null) {
            stmt.bindLong(1, hid);
        }
 
        String hwid = entity.getHwid();
        if (hwid != null) {
            stmt.bindString(2, hwid);
        }
 
        String hwname = entity.getHwname();
        if (hwname != null) {
            stmt.bindString(3, hwname);
        }
    }

    @Override
    public Void readKey(Cursor cursor, int offset) {
        return null;
    }    

    @Override
    public HwList readEntity(Cursor cursor, int offset) {
        HwList entity = new HwList( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // hid
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // hwid
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // hwname
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, HwList entity, int offset) {
        entity.setHid(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setHwid(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setHwname(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final Void updateKeyAfterInsert(HwList entity, long rowId) {
        // Unsupported or missing PK type
        return null;
    }
    
    @Override
    public Void getKey(HwList entity) {
        return null;
    }

    @Override
    public boolean hasKey(HwList entity) {
        // TODO
        return false;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "hwList" to-many relationship of Inventory. */
    public List<HwList> _queryInventory_HwList(Long hid) {
        synchronized (this) {
            if (inventory_HwListQuery == null) {
                QueryBuilder<HwList> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Hid.eq(null));
                inventory_HwListQuery = queryBuilder.build();
            }
        }
        Query<HwList> query = inventory_HwListQuery.forCurrentThread();
        query.setParameter(0, hid);
        return query.list();
    }

}
